home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / database / blobte / blob_tes.frm (.txt) next >
Encoding:
Visual Basic Form  |  1994-03-09  |  8.1 KB  |  245 lines

  1. VERSION 2.00
  2. Begin Form BLOB_Test 
  3.    BackColor       =   &H8000000F&
  4.    Caption         =   "BLOB Test Form"
  5.    ClientHeight    =   4296
  6.    ClientLeft      =   816
  7.    ClientTop       =   1476
  8.    ClientWidth     =   6372
  9.    Height          =   4692
  10.    Left            =   780
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   4296
  13.    ScaleWidth      =   6372
  14.    Top             =   1116
  15.    Width           =   6444
  16.    Begin CommandButton Command4 
  17.       Caption         =   "Add New Record"
  18.       Height          =   372
  19.       Left            =   2160
  20.       TabIndex        =   10
  21.       Top             =   3360
  22.       Width           =   1692
  23.    End
  24.    Begin TextBox Text2 
  25.       DataField       =   "Input_Size"
  26.       DataSource      =   "Data1"
  27.       Enabled         =   0   'False
  28.       Height          =   288
  29.       Index           =   2
  30.       Left            =   120
  31.       TabIndex        =   9
  32.       Top             =   3120
  33.       Width           =   972
  34.    End
  35.    Begin TextBox Text2 
  36.       DataField       =   "File_Name"
  37.       DataSource      =   "Data1"
  38.       Enabled         =   0   'False
  39.       Height          =   288
  40.       Index           =   1
  41.       Left            =   120
  42.       TabIndex        =   8
  43.       Top             =   2760
  44.       Width           =   6012
  45.    End
  46.    Begin TextBox Text2 
  47.       DataField       =   "CNT"
  48.       DataSource      =   "Data1"
  49.       Enabled         =   0   'False
  50.       Height          =   288
  51.       Index           =   0
  52.       Left            =   120
  53.       TabIndex        =   7
  54.       Top             =   2400
  55.       Width           =   972
  56.    End
  57.    Begin CommandButton Command3 
  58.       Caption         =   "Write File"
  59.       Height          =   372
  60.       Left            =   4440
  61.       TabIndex        =   4
  62.       Top             =   1800
  63.       Width           =   1812
  64.    End
  65.    Begin CommandButton Command2 
  66.       Caption         =   "Read File"
  67.       Height          =   372
  68.       Left            =   2400
  69.       TabIndex        =   3
  70.       Top             =   1800
  71.       Width           =   1812
  72.    End
  73.    Begin TextBox Text1 
  74.       Height          =   288
  75.       Index           =   1
  76.       Left            =   120
  77.       TabIndex        =   2
  78.       Top             =   1320
  79.       Width           =   6132
  80.    End
  81.    Begin CommonDialog CMDialog1 
  82.       DefaultExt      =   "*.*"
  83.       DialogTitle     =   "Select File"
  84.       Filename        =   "*.*"
  85.       Filter          =   "All  (*.*)|*.*"
  86.       Left            =   5880
  87.       Top             =   0
  88.    End
  89.    Begin CommandButton Command1 
  90.       Caption         =   "Get File Name"
  91.       Height          =   372
  92.       Left            =   120
  93.       TabIndex        =   1
  94.       Top             =   1800
  95.       Width           =   2052
  96.    End
  97.    Begin Data Data1 
  98.       Caption         =   "Data1"
  99.       Connect         =   ""
  100.       DatabaseName    =   "BLOBTEST.MDB"
  101.       Exclusive       =   0   'False
  102.       Height          =   252
  103.       Left            =   2040
  104.       Options         =   0
  105.       ReadOnly        =   0   'False
  106.       RecordSource    =   "Blob_Test_Table"
  107.       Top             =   3840
  108.       Width           =   1872
  109.    End
  110.    Begin TextBox Text1 
  111.       Height          =   288
  112.       Index           =   0
  113.       Left            =   120
  114.       TabIndex        =   0
  115.       Top             =   480
  116.       Width           =   6132
  117.    End
  118.    Begin Label Label1 
  119.       BackColor       =   &H8000000F&
  120.       Caption         =   "Output File && Path Name"
  121.       FontBold        =   -1  'True
  122.       FontItalic      =   0   'False
  123.       FontName        =   "Arial"
  124.       FontSize        =   9.6
  125.       FontStrikethru  =   0   'False
  126.       FontUnderline   =   0   'False
  127.       Height          =   228
  128.       Index           =   1
  129.       Left            =   120
  130.       TabIndex        =   6
  131.       Top             =   1080
  132.       Width           =   3132
  133.    End
  134.    Begin Label Label1 
  135.       BackColor       =   &H8000000F&
  136.       Caption         =   "Input File && Path Name"
  137.       FontBold        =   -1  'True
  138.       FontItalic      =   0   'False
  139.       FontName        =   "Arial"
  140.       FontSize        =   9.6
  141.       FontStrikethru  =   0   'False
  142.       FontUnderline   =   0   'False
  143.       Height          =   228
  144.       Index           =   0
  145.       Left            =   120
  146.       TabIndex        =   5
  147.       Top             =   240
  148.       Width           =   3132
  149.    End
  150. Option Explicit
  151. Declare Function GetModuleFileName Lib "Kernel" (ByVal hModule As Integer, ByVal lpFilename As String, ByVal nSize As Integer) As Integer
  152. Sub Command1_Click ()
  153.     CMDialog1.Action = 1
  154.     Text1(0) = CMDialog1.Filename
  155.     Text1(1) = "C:\TEMP\" & CMDialog1.Filetitle
  156. End Sub
  157. Sub Command2_Click ()
  158.     If Data1.Recordset.RecordCount = 0 Then
  159.     Data1.Recordset.AddNew
  160.     Data1.Recordset.Update
  161.     End If
  162.     If (Len(Text1(0)) = 0) Then
  163.     MsgBox "Require File Name To Read." & Chr(10) & "Select 'Get File Name' first."
  164.     Exit Sub
  165.     End If
  166.     ReadBigFile (Text1(0))
  167. End Sub
  168. Sub Command3_Click ()
  169.     If (Len(Text1(1)) = 0) Then
  170.     MsgBox "Require File Name To Read." & Chr(10) & "Select 'Get File Name' first or edit 'Output File Name'."
  171.     Exit Sub
  172.     End If
  173.     WriteBigFile (Text1(1))
  174. End Sub
  175. Sub Command4_Click ()
  176.     Data1.Recordset.AddNew
  177.     Data1.Recordset.Update
  178. End Sub
  179. Sub Form_Load ()
  180.     Dim temp As String
  181.     temp = Left$(App.Path, 1)
  182.     ChDrive temp
  183.     ChDir App.Path
  184. End Sub
  185. Sub ReadBigFile (FName As String)
  186. 'AppendChunk Method Example
  187. 'This example uses AppendChunk with a data control to save the contents of a separate file into a field.  You would call this
  188. 'procedure with the path and name of the file you want to put into your database.  This procedure works for either Memo or Long
  189. 'Binary fields.
  190.     Dim TotalSize As Long, CurChunk As String
  191.     Dim I As Integer, FNum As Integer, ChunkSize As Integer
  192.     Screen.MousePointer = 11
  193.     ChunkSize = 12000       ' Set size of chunk.
  194.     Data1.Recordset.Edit    ' Enter Edit mode.
  195.     Data1.Recordset.Fields(Field_Name) = "" ' Clear Comments field.
  196.     FNum = FreeFile ' Get free file number.
  197.     Open FName For Binary As #FNum  ' Open the file.
  198.     TotalSize = LOF(FNum)
  199.     Text2(1) = FName
  200.     Text2(2) = TotalSize
  201.     Do While Not EOF(FNum)
  202.         If TotalSize - Seek(FNum) < ChunkSize Then
  203.             ChunkSize = TotalSize - Seek(FNum)
  204.             If ChunkSize <= 0 Then Exit Do
  205.         End If
  206.         CurChunk = String$(ChunkSize + 1, 32)
  207.         Get #FNum, , CurChunk   ' Read chunk from file.
  208.     ' Append chunk to Comments field.
  209.         Data1.Recordset.Fields(Field_Name).AppendChunk (CurChunk)
  210.     Loop
  211.     Data1.Recordset.Update  ' Save the record.
  212.     Close FNum      ' Close the file.
  213.     Screen.MousePointer = 0
  214.     MsgBox "Stored file " & FName & Chr(10) & "Input file size = " & TotalSize & Chr(10) & "Into '" & Field_Name & "'."
  215. End Sub
  216. Sub WriteBigFile (FName As String)
  217. 'GetChunk and FieldSize Methods Example
  218. 'This example uses GetChunk with a data control to save the contents of a field to a separate file.  You would call this procedure
  219. 'with the path and name of the file where you want to save the contents of the field.  This procedure works for either text or binary
  220. 'fields.
  221.     Dim NumChunks As Long, TotalSize As Long
  222.     Dim RemChunk As Integer, CurSize As Integer
  223.     Dim I As Integer, FNum As Integer, CurChunk As String
  224.     Screen.MousePointer = 11
  225.     ChunkSize = 2000        ' Set size of chunk.
  226.     ' Get field size.
  227.     TotalSize = Data1.Recordset.Fields(Field_Name).FieldSize()
  228.     NumChunks = TotalSize \ ChunkSize       ' Set number of chunks.
  229.     ' Set number of remaining bytes.
  230.     RemChunk = TotalSize Mod ChunkSize
  231.     ' Set starting size of chunk.
  232.     CurSize = ChunkSize
  233.     FNum = FreeFile ' Get free file number.
  234.     Open FName For Binary As #FNum  ' Open the file.
  235.     For I = 0 To NumChunks
  236.         If I = NumChunks Then CurSize = RemChunk
  237.         CurChunk = Data1.Recordset.Fields(Field_Name).GetChunk(I * ChunkSize, CurSize)
  238.         Put #FNum, , CurChunk   ' Write chunk to file.
  239.     Next I
  240.     TotalSize = LOF(FNum)
  241.     Close FNum
  242.     Screen.MousePointer = 0
  243.     MsgBox "Output file " & FName & Chr(10) & "Output file size = " & TotalSize & Chr(10) & "From '" & Field_Name & "'."
  244. End Sub
  245.